﻿/****************************************************************************************************
	Copyright (C) 2010 RapidWebDev Organization (http://rapidwebdev.org)
	Author: Eunge, Legal Name: Jian Liu, Email: eunge.liu@RapidWebDev.org

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ****************************************************************************************************/

using System;
using System.IO;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Configuration;
using System.Linq;
using System.Linq.Expressions;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Web;
using System.Web.SessionState;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BaoJianSoft.Common;
using BaoJianSoft.Common.Caching;
using BaoJianSoft.Common.Web;
using BaoJianSoft.Platform.Linq;

namespace BaoJianSoft.Platform.Services
{
	/// <summary>
	/// The service to operate organizations for the authenticated user.
	/// </summary>
	[ServiceContract(Name = "OrganizationService", Namespace = ServiceNamespaces.Membership, SessionMode = SessionMode.Allowed)]
	public interface IOrganizationService
	{
		/// <summary>
		/// Search organizations by a collection of criterias for the authenticated user of request.
		/// </summary>
		/// <param name="domain">Which domain of the searching organizations.</param>
		/// <param name="orgTypeId">Which organization type the searching organizations should belong to.</param>
		/// <param name="q">Keywords for searching.</param>
		/// <param name="sortField">Sorting field name, the default sorting field is LastUpdatedDate.</param>
		/// <param name="sortOrder">Sorting order, DESC or ASC, the default sorting order is DESC.</param>
		/// <param name="start">The start organization index of hit to return.</param>
		/// <param name="limit">The limit of returned organizations.</param>
		/// <returns>The query results object includes total hit count, returned records, start and limit.</returns>
		[OperationContract]
		[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "json/search?domain={domain}&q={q}&start={start}&limit={limit}&sortfield={sortField}&sortDirection={sortDirection}&orgTypeId={orgTypeId}")]
		QueryResultObject SearchJson(string domain, string orgTypeId, string q, string sortField, string sortDirection, int start, int limit);

		/// <summary>
		/// Get first organization matching the specified query. 
		/// The matching algorithm is to try to search organizations in following order. Once an organization is found, it's returned as the result.
		/// 1) completely match organization code;
		/// 2) completely match organization name;
		/// 3) match whether there has organizations with code starts with specified query;
		/// 4) match whether there has organizations with name starts with specified query;
		/// </summary>
		/// <param name="domain"></param>
		/// <param name="q"></param>
		/// <returns></returns>
		[OperationContract]
		[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "json/get?domain={domain}&q={q}")]
		OrganizationObject GetJson(string domain, string q);

		/// <summary>
		/// Find organization types in specified domain.
		/// </summary>
		/// <param name="domain"></param>
		/// <returns></returns>
		[OperationContract]
		[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "json/FindOrganizationTypes/{domain}")]
		QueryResultObject FindOrganizationTypesJson(string domain);

		/// <summary>
		/// Lists all available organization domains.
		/// </summary>
		/// <returns></returns>
		[OperationContract]
		[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "json/ListDomains")]
		Collection<OrganizationDomainObject> ListDomainsJson();
	}
}
